package com.itheima.exerciseTest.method40_49.method44;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

// 服务器
public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10009);

        ThreadPoolExecutor pool = new ThreadPoolExecutor(3,
                5,
                1, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());


        while (true) {
            Socket accept = ss.accept();
            ThreadServer ts = new ThreadServer(accept);
            pool.submit(ts);
        }
    }
}
